package leetcode.editor.cn.q1_300.q150;

import java.util.Arrays;

/**
 * 投票法就很灵性，这里没有抄，可以看一下答案
 *
 * @author qidi
 * @date 2022-02-10 16:41:43
 */
class Q0169_MajorityElement {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int majorityElement(int[] nums) {
            int n = nums.length;
            if (n < 3) return nums[0];
            Arrays.sort(nums);

            return nums[n / 2];
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0169_MajorityElement().new Solution();
        System.out.println(solution.majorityElement(new int[]{3, 2, 3}));
        System.out.println(solution.majorityElement(new int[]{2, 2, 1, 1, 1, 2, 2}));
    }
}